package cn.com.dcsgo.api;

import cn.com.dcsgo.model.search.SkuEs;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * SearchApiController
 *
 * @author Dcsgo
 * @since 2025/4/25 9:48
 */
@Api(tags = "ES")
@RestController
@RequestMapping("api/search")
@RequiredArgsConstructor
public class SearchApiController {
    private final SkuService skuService;

    @ApiOperation("通过 skuId 删除ES中的SKU数据")
    @DeleteMapping("sku/{id}")
    public Result<Serializable> delete(@PathVariable Long id) {
        skuService.deleteById(id);
        return Result.ok(null);
    }

    @ApiOperation("通过 skuId 向ES中添加SKU数据")
    @PostMapping("sku/{id}")
    public Result<Serializable> add(@PathVariable Long id) {
        skuService.insertById(id);
        return Result.ok(null);
    }

    @ApiOperation("获取指定数量的热门商品信息")
    @GetMapping("sku/hot/count/{number}")
    public List<SkuEs> getEsHotSkuInfoByCount(@PathVariable Integer number) {
        return skuService.getHotSkuInfoByCount(number);
    }

    @ApiOperation("通过skuId更新sku热度")
    @PutMapping("sku/{skuId}/hot")
    public boolean plusSkuHotScore(@PathVariable Long skuId) {
        skuService.plusSkuHotScore(skuId);
        return true;
    }
}
